<?php
/*
 * @Author: lokei
 * @Date: 2022-09-19 13:45:10
 * @LastEditors: lokei
 * @LastEditTime: 2022-11-20 10:42:34
 * @Description: 
 */
namespace App\Http\Controllers\Activity\Gift;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Activity\Gift\GiftModel;
use Illuminate\Http\Request;

class GiftController extends Controller
{
	public function get(Request $request)
	{
		$gift = GiftModel::where('id', '=', $request->input('id'))->first();
		$res = ResultTool::success();
		$res['data'] = $gift;
		return $res;
	}
	public function list(Request $request)
	{
		if(!is_null($request->input('status')) && $request->input('status') != '') {
			$items = GiftModel::where('status', '=', $request->input('status'))->get();
		} else {
			$items = GiftModel::get();
		}
		$data['items'] = $items;
		$data['total'] = count($items);
		$res = ResultTool::success();
		$res['data'] = $data;
		return $res;
	}
	
	public function update(Request $request)
	{
		$status = '0';
		$gift = GiftModel::where('id', '=', $request->input('id'))->first();
		$gift->name = $request->input('name');
		$gift->img_thumb = $request->input('img_thumb');
		$gift->img_display = $request->input('img_display');
		$gift->intro = $request->input('intro');
		$gift->detail = $request->input('detail');
		$gift->amount = $request->input('amount');
		$gift->sales = $request->input('sales');
		$gift->save();
		$data['status'] = $status;
		$res['data'] = $data;
		return $res;
	}
	public function create(Request $request)
	{
		$status = '0';
		$gift = new GiftModel();
		$gift->name = $request->input('name');
		$gift->img_thumb = $request->input('img_thumb');
		$gift->img_display = $request->input('img_display');
		$gift->intro = $request->input('intro');
		$gift->detail = $request->input('detail');
		$gift->created_at = date('Y-m-d H:i:s', time());
		$gift->amount = $request->input('amount');
		$gift->sales = $request->input('sales');
		$gift->save();
		$data['status'] = $status;
		$res['data'] = $data;
		return $res;
	}
	public function delete(Request $request)
	{
		GiftModel::where('id', '=', $request->input('id'))->delete();
		$data['status'] = '0';
		$res['data'] = $data;
		return $res;
	}
}
